package shape3D;     

import javafx.application.Application;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.*;
import javafx.scene.transform.Rotate;

// 盒子(带有材质和相机,还可以用TriangleMesh创建自定义3D图形;可以和2D图形共存,但要注意遮挡)
public class BoxDemo extends Application { 
	private VBox root = new VBox(5);
	private Box box;
	private Color[] colors = {Color.PURPLE, Color.BLUEVIOLET, Color.BLUE, Color.GREEN,
								Color.GREENYELLOW, Color.YELLOW, Color.ORANGE, Color.RED};
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		root.setTranslateX(100);
		root.setTranslateY(30);
		
		// setDiffuseMap(设置贴图),setDiffuseColor(设置颜色)
		for(int i=0; i<8; i++) {
			box = new Box(200, 40, 60);
			box.setMaterial(new PhongMaterial(colors[i]));		
			box.setRotationAxis(Rotate.Y_AXIS);		// 绕y轴旋转
			box.setRotate(30);
			root.getChildren().addAll(box);
		}
		
		Scene scene = new Scene(root, 700, 500, true);		// 开启3D效果
		PerspectiveCamera pc = new PerspectiveCamera();		// 透视相机(默认为平行相机)
		pc.setTranslateX(30);		// 设置位移(位移不受布局约束),旋转(默认位置在中央)
		pc.setRotationAxis(Rotate.Y_AXIS);
//		pc.setRotate(30);
		pc.setFieldOfView(30);		// 设置相机的视野大小(竖直方向),默认为30
		scene.setCamera(pc);		
		stage.setScene(scene);
		stage.show();
	}
}





